package handle

import (
	"context"
	"week1zk-project/api/pkg"
	pb "week1zk-project/user-rpc/api/user"
	"week1zk-project/user-rpc/internal/model"
)

// 定义空接口

type UserInfoService struct {
	pb.UnimplementedUserServiceServer
}

func (s *UserInfoService) UserRegister(ctx context.Context, req *pb.UserRegisterRequest) (*pb.UserRegisterResponse, error) {
	u := model.User{
		Username:   req.Username,
		Password:   pkg.Md5(req.Password),   //MD5加密
		ConfirmPwd: pkg.Md5(req.ConfirmPwd), //MD5加密
		Email:      req.Email,
		Mobile:     req.Mobile,
	}
	err := u.Register()
	if err != nil {
		return &pb.UserRegisterResponse{
			Code: 400,
			Msg:  "用户注册失败",
		}, err
	}
	return &pb.UserRegisterResponse{
		Code:   200,
		Msg:    "用户注册成功",
		UserId: int64(u.ID),
	}, nil
}
